﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using GalaSoft.MvvmLight;
using System.Windows.Input;
using GalaSoft.MvvmLight.Command;
using System.Windows;

namespace MvvmDialogBehaviorSample
{
    public class LoginDialogViewModel:ViewModelBase
    {
        private Action _CloseAction;

        public LoginDialogViewModel(Action closeAction)
        {
            WindowTitle = "LoginDialogWindowTitle";
            _CloseAction = closeAction;
            WindowState = System.Windows.WindowState.Normal;
        }

        private WindowState _WindowState;
        public WindowState WindowState
        {
            get { return _WindowState; }
            set
            {
                if (_WindowState != value)
                {
                    _WindowState = value;
                    RaisePropertyChanged("WindowState");
                }
            }
        }

        private String _WindowTitle;
        public String WindowTitle
        {
            get { return _WindowTitle; }
            set
            {
                if (_WindowTitle != value)
                {
                    _WindowTitle = value;
                    RaisePropertyChanged("WindowTitle");
                }
            }
        }

        private String _UserName;
        public String UserName
        {
            get { return _UserName; }
            set
            {
                if (_UserName != value)
                {
                    _UserName = value;
                    RaisePropertyChanged("UserName");
                }
            }
        }

        private String _Password;
        public String Password
        {
            get { return _Password; }
            set
            {
                if (_Password != value)
                {
                    _Password = value;
                    RaisePropertyChanged("Password");
                }
            }
        }

        private ICommand _LoginCommand;
        public ICommand LoginCommand
        {
            get
            {
                if (_LoginCommand == null)
                {
                    _LoginCommand = new RelayCommand(Login);
                }

                return _LoginCommand;
            }
        }

        private void Login()
        {
            if (DoLogin())
            {
                _CloseAction();
            }
        }

        private ICommand _CancelCommand;
        public ICommand CancelCommand
        {
            get
            {
                if (_CancelCommand == null)
                {
                    _CancelCommand = new RelayCommand(Cancel);
                }

                return _CancelCommand;
            }
        }

        private void Cancel()
        {
            _CloseAction();
        }

        private bool DoLogin()
        {
            // Login Process...
            return true;
        }
    }
}
